<template>
  <page-header-wrapper>
    <a-button @click="newShow = true" type="primary">
      新增
    </a-button>
    <a-table :columns="columns" :data-source="listData" :loading="loading" :pagination="false">
      <span slot="action" slot-scope="text, record">
        <template>
          <a @click="del(record)">删除</a>
        </template>
      </span>
    </a-table>
    <a-modal v-model="newShow" title="新增" @ok="neww">
      <a-input v-model="text"/>
    </a-modal>

    <a-modal v-model="editShow" title="编辑" @ok="save">
      <a-input v-model="text"/>
    </a-modal>
  </page-header-wrapper>
</template>

<script>

export default {
  name: 'TableList',
  // components: {
  //   STable
  // },
  data () {
    return {
      loading: false,
      editShow: false,
      newShow: false,
      pagesize: 20,
      searchText: '',
      text: '',
      current: {},
      listData: [],
      // 表头
      columns: [
        {
          title: '宿舍楼',
          dataIndex: 'name'
        },
        {
          title: '创建人id',
          dataIndex: 'createPersonID'
        },
        {
          title: '创建时间',
          dataIndex: 'createTime'
        },
        {
          title: '操作',
          dataIndex: 'action',
          width: '250px',
          scopedSlots: { customRender: 'action' }
        }
      ]
    }
  },
  created () {
    this.getList()
  },
  methods: {
    getList () {
      this.loading = true
      this.fetchList('/dormitory/getBySchool').then(res => {
        this.listData = res.data
        this.loading = false
      })
    },
    // save () {
    //   console.log(this.text)
    //   this.loading = true
    //   const item = this.current
    //   item.name = this.text
    //   this.fetchList('/dormitory/update', item).then(data => {
    //     this.getList()
    //     this.editShow = false
    //   })
    // },
    neww () {
      const item = {
        Name: this.text
      }
      this.fetchList('/dormitory/new', item).then(data => {
        this.getList()
        this.newShow = false
      })
    },
    edit (item) {
      this.current = item
      this.text = item.name
      this.editShow = true
    },
    del (item) {
      item.deleted = 1
      this.loading = true
      this.fetchList('/dormitory/update', item).then(data => {
        this.getList()
      })
    }
  }
}
</script>
